import { getCookie, setCookie } from '@/utils/cookie'
import { defineStore } from 'pinia'
import { ref } from 'vue'

// 存储token
export const UserToken = defineStore('userToken', () => {
  const token = ref(getCookie('token') || '')
  const saveToken = (data: string) => {
    token.value = data
    setCookie('token', data)
  }

  return { token, saveToken }
})

// 收藏产品数量
export const CollectNum = defineStore('collectNum', () => {
  const collectNum = ref(getCookie('collectNum') || 0)
  const saveCollect = (data: number) => {
    collectNum.value = data
    setCookie('collectNum', data)
  }

  return { collectNum, saveCollect }
})

// 购物车数量
export const ShopcartNum = defineStore('shopcartnum', () => {
  const shopcartNum = ref(getCookie('num') || 0)
  const saveNum = (data: number) => {
    shopcartNum.value = data
    setCookie('num', data)
  }

  return { shopcartNum, saveNum }
})
